﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Calendar.Domain;

namespace Calendar.GUI
{
    public partial class WorkForm : Form
    {
        public AddDateWorkHandler AddDateWorkEvent = null;
        WorkHandler _workHandler;

        public WorkForm()
        {
            InitializeComponent();
        }

        public WorkForm(WorkHandler workHandler)
        {
            InitializeComponent();
            SetAddWorkButton();
            _workHandler = workHandler;
            workNameTextBox.SelectedText = null;
            emergancyLevelComboBox.SelectedIndex = (int)Emergency.ImportantEmergent;
        }

        public void SetAddWorkButton()
        {
            Button addWorkButton = new Button();
            addWorkButton.Location = new Point(100, 216);
            addWorkButton.Name = "addWorkButton";
            addWorkButton.Size = new Size(75, 23);
            addWorkButton.TabIndex = 2;
            addWorkButton.Text = "加入工作";
            addWorkButton.UseVisualStyleBackColor = true;
            addWorkButton.Click += new EventHandler(this.addWorkButton_Click);
            Controls.Add(addWorkButton);
        }

        private void addWorkButton_Click(object sender, EventArgs e)
        {
            string name = workNameTextBox.Text;
            DateTime startTime = startDateTimePicker.Value;
            DateTime deadline = deadlineDateTimePicker.Value;
            int emergencyLevel = emergancyLevelComboBox.SelectedIndex;
            int progress = progressTrackBar.Value;

            _workHandler.AddWork(name, startTime, deadline, emergencyLevel, progress);         
            this.Close();
        }

        private void progressTrackBar_Scroll(object sender, EventArgs e)
        {
            percentageLabel.Text = progressTrackBar.Value.ToString() + " %";
        }
    }
}
